﻿@model EC_ASS.Models.Category

@if (!(String.IsNullOrEmpty(ViewBag.CMSG)))
{
    <div class="alert alert-success">@ViewBag.CMSG</div>
}
else
{
    <form action="@Url.Action("EditCategory", "Admin")" class="form-horizontal" 
                 style="margin-top: 20px;" id="editCatForm" method="post">
        <div class="control-group">
            <label class="control-label" for="inputName">Tên</label>
            <div class="controls">
                <input type="text" id="inputName" name="Name" value="@Model.Name" required />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="inputDescription">Mô tả</label>
            <div class="controls">
                <input type="text" id="inputDescription" value="@Model.Description" name="Description" required />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="inputPrefix">Loại</label>
            <div class="controls">
                <select name="Prefix" required>
                    <option value="PA">Áo</option>
                    <option value="PQ">Quần</option>
                    <option value="PG">Giày</option>
                    <option value="PK">Phụ kiện</option>
                </select>
            </div>
        </div>
        <div class="control-group">
            <div class="controls">
                <button type="submit" class="btn">Cập nhật</button>
            </div>
        </div>
    </form>
}
<!--Submit add form-->
<script>
    $(function () {
        $('#editCatForm').submit(function (e) {
            e.preventDefault();
            $('#editLoading').show();
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result) {
                    $('#editLoading').hide();
                    $('#editModalContent').html('<div class="alert alert-success">Cập nhật thành công!</div>');
                    setTimeout(function () {
                        $('#editModal').modal('hide');
                    }, 2000);
                    setTimeout(function () {
                        $('#listTable').load('@Url.Action("_ListCategory", "Admin")').hide().fadeIn('slow');
                    }, 2000);
                }
            });
            return false;
        });
    });
</script>